//
//  CustomerDetailModel.swift
//  Employee
//
//  Created by tancheng on 2018/7/23.
//  Copyright © 2018年 remotevillage. All rights reserved.
//

import Foundation
import SwiftyJSON


func getCunstomerTypeDesc(_ type: CustomerType) -> String {
    switch type {
    case .owner:
        return "业主"
    case .tenant:
        return "租客"
    case .vistor:
        return "访客"
    case .everowner:
        return "老业主"
    case .evertenant:
        return "老租客"
    }
}

enum CustomerType: String {
    case owner = "OWNER"
    case tenant = "TENANT"
    case vistor = "VISITOR"
    case everowner = "EVEROWNER"
    case evertenant = "EVERTENANT"
}
//case OWNER = "业主"
//case TENANT = "租客"
//case VISITOR = "访客"
//case EVEROWNER = "老业主"
//case EVERTENANT = "老租客"

struct CustomerDetailModel: ModelProtocol {
    
    let carSites: [CarSiteModel]
    let cars: [CarModel] //json
    let diploma: String
    let houses: [CustomerHouseModel]
    let id: String
    let idCard: String
    let maritalStatus: String
    let name: String
    let nationId: String
    let nationName: String
    let number: String
    let phone: String
    let regResidence: String
    let remark: String
    let sosName: String
    let sosPhone: String
    var tags: [TagModel] //json
    
    init(json: JSON) {
        
        carSites = CarSiteModel.array(from: json["carSites"].arrayValue)
        cars = CarModel.array(from: json["cars"].arrayValue)
        diploma = json["diploma"].stringValue
        houses = CustomerHouseModel.array(from: json["houses"].arrayValue)
        id = json["id"].stringValue
        idCard = json["idCard"].stringValue
        maritalStatus = json["maritalStatus"].stringValue
        name = json["name"].stringValue
        nationId = json["nationId"].stringValue
        nationName = json["nationName"].stringValue
        number = json["number"].stringValue
        phone = json["phone"].stringValue
        regResidence = json["regResidence"].stringValue
        remark = json["remark"].stringValue
        sosName = json["sosName"].stringValue
        sosPhone = json["sosPhone"].stringValue
        tags = TagModel.array(from: json["tags"].arrayValue)
        
    }
    
    static func array(from jsonArray: [JSON]) -> [CustomerDetailModel] {
         return jsonArray.map({CustomerDetailModel.init(json: $0)})
    }
    
    
}

struct TagModel: ModelProtocol {
    
    let id: String
    let name: String
    
    init(json: JSON) {
        id = json["tagId"].stringValue
        name = json["tagName"].stringValue
    }
    
    static func array(from jsonArray: [JSON]) -> [TagModel] {
         return jsonArray.map({TagModel.init(json: $0)})
    }
    
    
}

struct CarModel: ModelProtocol {
    
    let id: String
    let cardType: String
    let carNumber: String
    let carAreaName: String
    
    init(json: JSON) {
        id = json["id"].stringValue
        cardType = json["cardType"].stringValue
        carNumber = json["carNumber"].stringValue
        carAreaName = json["carAreaName"].stringValue
    }
    
    static func array(from jsonArray: [JSON]) -> [CarModel] {
        return jsonArray.map({CarModel.init(json: $0)})
    }
    
    
}


struct CarSiteModel {
    
    let carNumber: String
    var customerType: CustomerType = .owner
    let id: String
    let numberDesc: String
    
    init(json: JSON) {
        if let type = CustomerType(rawValue: json["customerType"].stringValue) {
            customerType = type
        }
        id = json["id"].stringValue
        carNumber = json["carNumber"].stringValue
        numberDesc = json["numberDesc"].stringValue
    }
    
    static func array(from jsonArray: [JSON]) -> [CarSiteModel] {
        return jsonArray.map({CarSiteModel.init(json: $0)})
    }
}

struct CustomerHouseModel {
    
    let customerId: String
    var customerType: CustomerType = .owner
    let id: String
    let houseId: String
    let numberDesc: String
    let ownership: Bool
    
    init(json: JSON) {
        if let type = CustomerType(rawValue: json["customerType"].stringValue) {
            customerType = type
        }
        id = json["id"].stringValue
        customerId = json["customerId"].stringValue
        numberDesc = json["numberDesc"].stringValue
        houseId = json["houseId"].stringValue
        ownership = json["ownership"].boolValue
    }
    
    static func array(from jsonArray: [JSON]) -> [CustomerHouseModel] {
        return jsonArray.map({CustomerHouseModel.init(json: $0)})
    }
}

struct CustomerDetailSend {
    var id = ""
}
